import java.util.*;

class JdbcTest
{
	//Print our main menu
	public static void printMenu()
	{
        System.out.println("Person-DB Hovedmeny");
        System.out.println("1. List all persons");
        System.out.println("2. List all childless persons");
        System.out.println("3. Search for last name");
        System.out.println("4. Quit");
	}
	
	public static void main(String[] args)
    {
		//Used for selection in the menu
		int command = 0;
		Scanner sc = new Scanner(System.in);
		
		//The database object we use to interface with the derby database
		Db dbObj = new DerbyDb();
		
		//Main application loop
		while (command != 4)
		{
			printMenu();
			
			//Read the command
			command = sc.nextInt();
			ArrayList<Person> results = null; //Used to store the result from queries
			
			switch (command)
			{
			case 1:
				System.out.println("All persons:");
				results = dbObj.getAllPersons(); //Retrieve a list of all persons in the database 
				break;
				
			case 2:
				System.out.println("All childless persons:");
				results = dbObj.getChildlessPersons(); //Retrieve a list of all childless persons in the database
				break;
				
			case 3:
				System.out.println("Please enter a search keyword:");
				String lname = sc.next();
				System.out.println("Searching for \"" + lname + "\"...");
				results = dbObj.searchLastName(lname);
				break;
				
			case 4:
				break;
				
			default:
				System.out.println("Invalid command.");
			}
			
			//If we have a non-empty result, print it.
			if (results != null)
			{
				for (Person p : results)
					System.out.println(p);
			}
			
			System.out.println("");
		}
		System.out.println("Goodbye!");

        Person p = new Person("Bob", "Blubb", 2010, 5);

    }
}
